package com.dqhl.community.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseMyAdapter;
import com.dqhl.community.view.ConfirmDialog;

/**
 * Created by LIENLIN on 2016/8/30.
 */
public class CollectionAdapter extends BaseMyAdapter {

    public CollectionAdapter(Context context) {
        super(context);
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder vh;
        if (view==null){
            vh=new ViewHolder();
            view= inflater.inflate(R.layout.collection_lv_item, viewGroup, false);
            vh.mIvLeft= (ImageView) view.findViewById(R.id.iv_left_collection);//商品头像
            vh.mIvDetail= (ImageView) view.findViewById(R.id.iv_detail_collection);//next按钮
            vh.mTvTitle= (TextView) view.findViewById(R.id.tv_title_collection);//主营
            vh.mTvTime= (TextView) view.findViewById(R.id.tv_time_collection);//营业时间
            vh.mTvDisplay= (TextView) view.findViewById(R.id.tv_collection_notcoll);//取消收藏
            view.setTag(vh);

        }else {
            vh= (ViewHolder) view.getTag();
        }

        vh.mTvDisplay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"点击了",Toast.LENGTH_SHORT).show();
                //弹出提示框
                final ConfirmDialog dialog = new ConfirmDialog(context, "确定取消收藏？", "确定", "取消");
                dialog.setButtonClickListener(new ConfirmDialog.ButtonClickListener() {
                    @Override
                    public void doConfirm() {
                        dialog.dismiss();
                    }

                    @Override
                    public void doCancel() {
                        dialog.dismiss();
                    }
                });
                dialog.show();
            }
        });

        return view;
    }
    class ViewHolder{
        ImageView mIvLeft,mIvDetail;
        TextView mTvTitle,mTvTime,mTvDisplay;
    }

}
